package suanfa.paixu;

import java.util.Arrays;

//插入排序
public class Insert {
    public static int[] insertsorted(int[] r){
        for(int i=1;i<r.length;i++) {
            //10,50,40,80,90
            while (i > 0 && r[i] < r[i - 1]) {//用于交换较小值于前面
                    int k = r[i];
                    r[i] = r[i - 1];
                    r[i - 1] = k;
                    i--;
            }
        }
        return r;
    }

    public static void main(String[] args) {
        int [] a={90,50,40,80,90};
        System.out.println(Arrays.toString(insertsorted(a)));
    }
}
